package com.example.qixin0314.bean;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.qixin0314.Activity.CompanyActivity;
import com.example.qixin0314.R;

import java.util.List;

public class recyclePictureAdapter extends RecyclerView.Adapter<recyclePictureAdapter.recyclePictureHolder> {

    private static final String TAG = recyclePictureAdapter.class.getSimpleName();
    private List<recyclePictureModel> list;

    public void setList(List<recyclePictureModel> list) {
        this.list = list;
    }

    private Context context;

    public recyclePictureAdapter(Context context) {
        this.context = context;
    }


    @NonNull
    @Override
    public recyclePictureHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new recyclePictureHolder(LayoutInflater.from(context).inflate(R.layout.recycle_picture_item, null));
    }

    @Override
    public void onBindViewHolder(@NonNull recyclePictureAdapter.recyclePictureHolder holder, int position) {
        if (!list.get(position).getPurl().isEmpty()) {
            //with()方法创建对象
            Glide.with(context).load(list.get(position).getPurl()).into(holder.itemImage);
        }
        else {
            holder.itemImage.setImageResource(R.drawable.shouye);
        }

        holder.itemImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, CompanyActivity.class);
                intent.putExtra("uri","http://m.qxswt.com/company/"+list.get(position).getId());
                intent.putExtra("name",list.get(position).getPname());
                intent.putExtra("puri",list.get(position).getPurl());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return null != list ? list.size() : 0;
    }

    class recyclePictureHolder extends RecyclerView.ViewHolder {
        ImageView itemImage;

        public recyclePictureHolder(@NonNull View itemView) {
            super(itemView);
            itemImage = itemView.findViewById(R.id.recycle_imag);
        }
    }
}
